From 22a4c15b4fcc1c17e38ce745d905d688d15093d0 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Sat, 19 Nov 2011 12:59:39 +0100 Subject: [PATCH] rbtree: Split out a common function gtk_rbtree_adjust() will adjust the summed values of a node and all its parents in the tree. Currently only implemented by splitting out the function from gtk_rbtree_free(). --- gtk/gtkrbtree.c | 55 +++++++++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/gtk/gtkrbtree.c b/gtk/gtkrbtree.c index 228abfece0..99261ad881 100644 --- a/gtk/gtkrbtree.c +++ b/gtk/gtkrbtree.c @@ -383,43 +383,54 @@ _gtk_rbtree_free (GtkRBTree *tree) g_free (tree); } +static void +gtk_rbnode_adjust (GtkRBTree *tree, + GtkRBNode *node, + int count_diff, + int total_count_diff, + int offset_diff) +{ + while (tree && node && node != tree->nil) + { + _fixup_validation (tree, node); + node->offset += offset_diff; + node->count += count_diff; + node->total_count += total_count_diff; + + node = node->parent; + if (node == tree->nil) + { + node = tree->parent_node; + tree = tree->parent_tree; + count_diff = 0; + } + } +} + void _gtk_rbtree_remove (GtkRBTree *tree) { +#ifdef G_ENABLE_DEBUG GtkRBTree *tmp_tree; - GtkRBNode *tmp_node; - - gint height = tree->root->offset; - guint total_count = tree->root->total_count; -#ifdef G_ENABLE_DEBUG if (gtk_get_debug_flags () & GTK_DEBUG_TREE) _gtk_rbtree_test (G_STRLOC, tree); #endif - tmp_tree = tree->parent_tree; - tmp_node = tree->parent_node; - /* ugly hack to make _fixup_validation work in the first iteration of the * loop below */ GTK_RBNODE_UNSET_FLAG (tree->root, GTK_RBNODE_DESCENDANTS_INVALID); - while (tmp_tree && tmp_node && tmp_node != tmp_tree->nil) - { - _fixup_validation (tmp_tree, tmp_node); - tmp_node->offset -= height; - tmp_node->total_count -= total_count; - - tmp_node = tmp_node->parent; - if (tmp_node == tmp_tree->nil) - { - tmp_node = tmp_tree->parent_node; - tmp_tree = tmp_tree->parent_tree; - } - } + gtk_rbnode_adjust (tree->parent_tree, + tree->parent_node, + 0, + - (int) tree->root->total_count, + - tree->root->offset); +#ifdef G_ENABLE_DEBUG tmp_tree = tree->parent_tree; - tmp_node = tree->parent_node; +#endif + _gtk_rbtree_free (tree); #ifdef G_ENABLE_DEBUG -- 2.30.2